import { getListApi as outWarehouseBroker } from "@/api/configCenter/outBoundAgent";
import { getListApi as departmentPersonnel, getAllCompanyApi } from "@/api/managementCenter/departmentPersonnel";
import { getListApi as getAllPaymentApi } from "@/api/configCenter/paymentManagement";
import { getTreeChannelApi } from "@/api/configCenter/warehouseEntryChannel";
import { getCustomerSelectList } from "@/api/managementCenter/customerManagement";

import { TreeSelect } from "ant-design-vue";
const SHOW_CHILD = TreeSelect.SHOW_CHILD;
import { reactive } from "vue";

export const searchItemList: Array<SuperSearch.SearchItem> = [
  {
    type: "input",
    label: "运单号",
    keyName: "waybillNums",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "客户简称",
    keyName: "customerIdList",
    optionsRequest: getCustomerSelectList,
    optReqParams: { isFilterChild: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "shortName",
      value: "id"
    },
    options: []
  }),
  {
    type: "input",
    label: "客户名称",
    keyName: "customerNames",
    placeholder: "支持批量(空格/逗号隔开)"
  },

  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "代理名称",
    keyName: "outWarehouseBrokerId",
    optionsRequest: outWarehouseBroker,
    optReqParams: { pageNum: 1, pageSize: 99999 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "name",
      value: "id"
    },
    options: []
  }),
  {
    type: "datetimerange",
    label: "拣货时间",
    keyName: "depositTime"
  },
  reactive<SuperSearch.SearchItem>({
    type: "cascader",
    label: "渠道",
    keyName: "channelIdList",
    optionsRequest: getTreeChannelApi,
    optReqParams: {},
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "label",
      value: "value",
      children: "children"
    },
    attrs: {
      multiple: true,
      showCheckedStrategy: SHOW_CHILD
    },
    options: []
  }),
  {
    type: "select",
    label: "对账状态",
    keyName: "checkingStatus",
    optConfig: {
      label: "label",
      value: "value"
    },
    options: [
      {
        label: "未入账",
        value: 0
      },
      {
        label: "对账中",
        value: 1
      },
      {
        label: "已入账",
        value: 2
      }
    ]
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "业务员",
    keyName: "bizId",
    optionsRequest: departmentPersonnel,
    optReqParams: { position: "4", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "账期",
    keyName: "accountPeriodIdList",
    optionsRequest: getAllPaymentApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "accountName",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "经营单位",
    keyName: "companyId",
    optionsRequest: getAllCompanyApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "name",
      value: "id"
    },
    options: []
  })
  // reactive<SuperSearch.SearchItem>({
  //   type: "select",
  //   label: "收货司机",
  //   keyName: "driverUserIdList",
  //   optionsRequest: getDriverApi,
  //   optReqParams: { pageNum: 1, pageSize: 9999999 },
  //   optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
  //     const { code, data } = res;
  //     if (code === 200) {
  //       row.options = data.records || [];
  //     }
  //   },
  //   optConfig: {
  //     label: "username",
  //     value: "userId"
  //   },
  //   attrs: {
  //     mode: "multiple"
  //   },
  //   options: []
  // })
];

// 列表
export const tableColumn: Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem> = [
  {
    type: "checkbox",
    field: "checkbox",
    minWidth: "50",
    fixed: "left"
  },
  {
    field: "waybillNum",
    title: "运单号",
    minWidth: "140"
  },
  {
    field: "shortName",
    title: "客户简称",
    minWidth: "100"
  },
  {
    field: "customerName",
    title: "客户名称",
    minWidth: "220"
  },
  {
    field: "accountName",
    title: "账期",
    minWidth: "100"
  },
  {
    field: "depositTime",
    title: "拣货时间",
    minWidth: "140",
    formatter: "formatDate"
  },
  {
    field: "checkingStatusName",
    title: "对账状态",
    minWidth: "80"
  },
  {
    field: "bizName",
    title: "业务员",
    minWidth: "80"
  },
  {
    field: "innerRemark",
    title: "内部备注",
    minWidth: "100"
  },
  {
    field: "outWarehouseBrokerName",
    title: "代理名称",
    minWidth: "110"
  },
  {
    field: "channelName",
    title: "预报渠道",
    minWidth: "160"
  },
  {
    field: "adjustCostSum",
    title: "成本调整",
    minWidth: "90"
  },
  {
    field: "receivablePrice",
    title: "应收金额",
    minWidth: "90"
  },
  {
    field: "addReceivablePrice",
    title: "应收追加",
    minWidth: "90"
  },
  {
    field: "receivableTotalPrice",
    title: "合计应收金额",
    minWidth: "90"
  },
  {
    field: "payablePrice",
    title: "应付金额",
    minWidth: "90"
  },
  {
    field: "addPayablePrice",
    title: "应付追加",
    minWidth: "90"
  },
  {
    field: "payableTotalPrice",
    title: "合计应付金额",
    minWidth: "90"
  },
  {
    field: "companyName",
    title: "经营单位",
    minWidth: "80"
  },
  // {
  //   field: "driverUserName",
  //   title: "收货司机",
  //   minWidth: "80"
  // },
  {
    field: "margin",
    title: "毛利润",
    minWidth: "90"
  }
];
